/*	$Id: conf.h 983 2009-09-01 02:45:42Z phrakt $	*/
/*
 * Copyright (c) 2004 Jean-Francois Brousseau <phrakt@gmail.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _CANOPY_CONF_H_
#define _CANOPY_CONF_H_

#include <canopy/htab.h>

#include <canopy/htab.h>


#define CONF_LINE_MAXLEN	1024
#define CONF_BUF_SIZE		1024
#define CONF_TOK_MAXLEN		1024
#define CNP_CONF_MAXINPUT	16

#define CONF_DIR_MAXARG		16

#define CONF_VAR_MAXNAMELEN	128

/* flags */
#define CONF_STRICTVAR    0x00000001	/* strict variable declaration */
#define CONF_STRICTDIR    0x00000002	/* strict directive checking */
#define CONF_VARSUBST     0x00000008	/* enable variable substitution */
#define CONF_MULTILINE    0x00000010	/* allow multiline statements */
#define CONF_PRAGMA       0x00000020	/* enable pragmas */
#define CONF_STRICT      (CONF_STRICTVAR | CONF_STRICTDIR)




/* error codes */
#define CONF_ERR_NOERR     0
#define CONF_ERR_BADNAME   1	/* invalid name */
#define CONF_ERR_STRICT    2	/* strict rule broken */
#define CONF_ERR_BADTOK    3	/* invalid token */
#define CONF_ERR_NOMEM     4	/* out of memory */
#define CONF_ERR_INVARG    5	/* invalid argument */
#define CONF_ERR_PARSE     6	/* unrecoverable parse error */
#define CONF_ERR_NOTSUP    7	/* operation not supported */
#define CONF_ERR_TOKLEN    8	/* token too long */
#define CONF_ERR_UNTQSTR   9	/* unterminated quoted string */
#define CONF_ERR_ARGC     10	/* argument count too large */



typedef struct cnp_conf_ctx cnp_conf_t;


cnp_conf_t* cnp_conf_alloc   (int);
void        cnp_conf_free    (cnp_conf_t *);
void        cnp_conf_reset   (cnp_conf_t *);
int         cnp_conf_setfl   (cnp_conf_t *, int);
int         cnp_conf_getfl   (cnp_conf_t *);
int         cnp_conf_parse   (cnp_conf_t *, const char *);
int         cnp_conf_parseln (cnp_conf_t *, const char *);
void        cnp_conf_clrerr  (cnp_conf_t *);
int         cnp_conf_geterr  (cnp_conf_t *);
int         cnp_conf_setvar  (cnp_conf_t *, const char *, const char *);
int         cnp_conf_getvar  (cnp_conf_t *, const char *, char *, size_t);
cnp_htab_t* cnp_conf_getvars (cnp_conf_t *);
int         cnp_conf_setdir  (cnp_conf_t *, const char *, int (*)(int, char **),
				int, int);


#endif /* _CANOPY_CONF_H_ */
